package cn.tedu.myIOC;

import org.junit.Test;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author :Colin
 * @version 创建时间: 2021/7/16 17:10
 */
public class MyIOC {
    //1.创建list，存bean
    private List<Bean> beans = new ArrayList<>();
    //@Test
    public MyIOC() throws Exception {
        Bean b3 =new Bean("111","111");
        Bean b1 = new Bean("hello","cn.tedu.spring.Hello");
        Bean b2 = new Bean("bird","cn.tedu.spring.Bird");
        beans.add(b1);
        beans.add(b2);
        //System.out.println(beans);[Bean{beanName='hello', beanPath='cn.tedu.spring.Hello'}, Bean{beanName='bird', beanPath='cn.tedu.spring.Bird'}]
        init();

    }
        Map<String, Object> map = new HashMap<>();
    private void init() throws Exception {

        for(Bean b:beans){
            String key = b.getBeanName();
            String quanlujing = b.getBeanPath();
            Object value = Class.forName(quanlujing).newInstance();
            map.put(key,value);
        }


        }
    public Object getBean(String beaname){
        return map.get(beaname);
    }

    //2.创建map，存对象{hello=new Hello（），user=new User（）}

}
